package com.zhouyu.beanfactory;

import com.zhouyu.service.OrderService;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.context.annotation.ConfigurationClassPostProcessor;

public class TimBeanFactoryRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor {

	//无法注册BeanDefinition 和@Configuration相关
	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
		beanFactory.registerSingleton("myOrderService",new OrderService());
		BeanDefinition bd = beanFactory.getBeanDefinition("userService");
//		bd.setAutowireCandidate();

	}
	/**	可以注册BeanDefinition,可以用于扫描
	 * @see ConfigurationClassPostProcessor#postProcessBeanDefinitionRegistry(BeanDefinitionRegistry)
	 */
	@Override
	public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
//		registry.registerBeanDefinition();
	}
}
